package com.fsnbigdata.repository;
import io.springlets.data.jpa.repository.support.QueryDslRepositorySupportExt;
import org.springframework.roo.addon.layers.repository.jpa.annotations.RooJpaRepositoryCustomImpl;
import com.fsnbigdata.domain.EnterpriseImage;
import com.fsnbigdata.domain.Enterprise;
import com.fsnbigdata.domain.QEnterpriseImage;
import com.querydsl.core.types.Path;
import com.querydsl.jpa.JPQLQuery;
import io.springlets.data.domain.GlobalSearch;
import io.springlets.data.jpa.repository.support.QueryDslRepositorySupportExt.AttributeMappingBuilder;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

/**
 * = EnterpriseImageRepositoryImpl
 *
 * TODO Auto-generated class documentation
 *
 */
@RooJpaRepositoryCustomImpl(repository = EnterpriseImageRepositoryCustom.class)
@Transactional(readOnly = true)
public class EnterpriseImageRepositoryImpl extends QueryDslRepositorySupportExt<EnterpriseImage> implements EnterpriseImageRepositoryCustom {

    /**
     * TODO Auto-generated constructor documentation
     */
    EnterpriseImageRepositoryImpl() {
        super(EnterpriseImage.class);
    }

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String ENTERPRISE = "enterprise";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String LOCATION = "location";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String CODE = "code";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String CREATE_DATE = "createDate";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String DESCRIPTION = "description";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String AUTHOR = "author";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String URL = "url";

    /**
     * TODO Auto-generated method documentation
     *
     * @param enterprise
     * @param globalSearch
     * @param pageable
     * @return Page
     */
    public Page<EnterpriseImage> findByEnterprise(Enterprise enterprise, GlobalSearch globalSearch, Pageable pageable) {
        QEnterpriseImage enterpriseImage = QEnterpriseImage.enterpriseImage;
        JPQLQuery<EnterpriseImage> query = from(enterpriseImage);
        Assert.notNull(enterprise, "enterprise is required");
        query.where(enterpriseImage.enterprise.eq(enterprise));
        Path<?>[] paths = new Path<?>[] { enterpriseImage.enterprise, enterpriseImage.code, enterpriseImage.description, enterpriseImage.location, enterpriseImage.author, enterpriseImage.url, enterpriseImage.createDate };
        applyGlobalSearch(globalSearch, query, paths);
        AttributeMappingBuilder mapping = buildMapper().map(ENTERPRISE, enterpriseImage.enterprise).map(CODE, enterpriseImage.code).map(DESCRIPTION, enterpriseImage.description).map(LOCATION, enterpriseImage.location).map(AUTHOR, enterpriseImage.author).map(URL, enterpriseImage.url).map(CREATE_DATE, enterpriseImage.createDate);
        applyPagination(pageable, query, mapping);
        applyOrderById(query);
        return loadPage(query, pageable, enterpriseImage);
    }
}
